package work.xiaohong.websocket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.xiaohong.websocket.dao.SingleMessageMapper;
import work.xiaohong.websocket.entity.SingleMessage;
import work.xiaohong.websocket.service.SingleMessageService;

import java.util.List;

@SuppressWarnings("all")
@Service
public class SingleMessageServiceImpl implements SingleMessageService {

    @Autowired
    private SingleMessageMapper singleMessageMapper;


    /**
     * 条件+分页查询SingleMessage
     * @param singleMessage 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<SingleMessage> findPage(SingleMessage singleMessage, int page, int size){
        // 构建查询条件
        QueryWrapper<SingleMessage> queryWrapper = new QueryWrapper<SingleMessage>(singleMessage);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return singleMessageMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询SingleMessage
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<SingleMessage> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return singleMessageMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法SingleMessage
     * @param singleMessage
     * @return
     */
    @Override
    public List<SingleMessage> findList(SingleMessage singleMessage){
        // 构建查询条件
        QueryWrapper<SingleMessage> queryWrapper = new QueryWrapper<SingleMessage>(singleMessage);
        // 查询数据
        return singleMessageMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除SingleMessage
     * @param id
     */
    @Override
    public void delete(java.math.BigInteger id){
        singleMessageMapper.deleteById(id);
    }

    /**
     * 根据Id批量删除SingleMessage数据
     * @param id
     */
    @Override
    public void deleteByIds(List<java.math.BigInteger> asList){
        singleMessageMapper.deleteBatchIds(asList);
    }


    /**
     * 根据ID修改SingleMessage
     * @param singleMessage
     */
    @Override
    public void updateById(SingleMessage singleMessage){
        // 初始化一些不可修改数据
        singleMessage.setGmtModified(null);
        singleMessage.setGmtCreate(null);
        singleMessage.setVersion(null);
        singleMessage.setDeleted(null);
        singleMessageMapper.updateById(singleMessage);
    }

    /**
     * 增加SingleMessage
     * @param singleMessage
     */
    @Override
    public void add(SingleMessage singleMessage){
        singleMessageMapper.insert(singleMessage);
    }

    /**
     * 根据ID查询SingleMessage
     * @param id
     * @return
     */
    @Override
    public SingleMessage findById(java.math.BigInteger id){
        return  singleMessageMapper.selectById(id);
    }

    /**
     * 查询全部SingleMessage数据
     * @return
     */
    @Override
    public List<SingleMessage> findAll() {
        return singleMessageMapper.selectList(null);
    }
}
